package net.xxcxcxcx.xc_enhancedmob.mixin;

import net.minecraft.entity.attribute.ClampedEntityAttribute;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClampedEntityAttribute.class)
public class ClampedEntityAttributeMixin extends EntityAttribute {

    protected ClampedEntityAttributeMixin(String translationKey, double fallback) {
        super(translationKey, fallback);
    }

    @Inject(at = @At("HEAD"), method = "clamp", cancellable = true)
    public void ClampedAttribute(double value, CallbackInfoReturnable<Double> cir) {
        switch (getTranslationKey()) {
            case "attribute.name.generic.max_health" -> {
                cir.setReturnValue(MathHelper.clamp(value, 1.0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.movement_speed" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.attack_damage" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.attack_speed" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.armor" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.luck" -> {
                cir.setReturnValue(MathHelper.clamp(value, -2000000000, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.flying_speed" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
            case "attribute.name.generic.attack_knockback" -> {
                cir.setReturnValue(MathHelper.clamp(value, 0, 2000000000));
                cir.cancel();
            }
        }
    }
}
